package com.fenghongzhang.kotlin1903.goods

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class GoodsViewModel : ViewModel(){

    //存货物的
    val goods = MutableLiveData<MutableList<Goods>>()


    fun getGoods(){
        val goods1 = Repository.getGoods()
        if(goods.value ==null){
            Log.i("init","1111")
            goods.value = goods1
        }
    }


    fun update(postion:Int,num:String){
        val good = goods.value
        if (good != null) {
            for(i in 0 until good.size){
                if(postion == i){
                    val goods1 = good[i]
                    goods1.goods_count = num
                    good[i] = goods1
                    goods.value?.set(postion, goods1)
                    Log.i("add","1234")
                }
            }
        }
    }


}